import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
import java.util.Vector;

public class DeviceSettings {

	private static String className = "DeviceSettings: ";
	private static String settingsFilePath = "config//device_settings.xml";

	public static void saveSettings(Vector<Device> devices) {
		DEBUG("saveSettings");

		Properties properties = new Properties();

		// START CONFIG
		for (int i = 0; i < devices.size(); i++) {
			Device device = devices.get(i);
			properties.setProperty(i + "_deviceID",
					Integer.toString(device.getDeviceID()));
			properties.setProperty(i + "_deviceName", device.getDeviceName());
		}
		// END CONFIG

		try {
			FileOutputStream fos = new FileOutputStream(settingsFilePath);
			properties.storeToXML(fos, "ScheduleSettings", "UTF-8");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void loadSettings() {
		DEBUG("loadSettings");
		Properties properties = new Properties();

		try {
			FileInputStream fis = new FileInputStream(settingsFilePath);
			properties.loadFromXML(fis);
		} catch (InvalidPropertiesFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return;
		}

		// START CONFIG

		// END CONFIG
	}

	private static void DEBUG(String debugString) {
		Macros.DEBUG(className + debugString);
	}
}
